package leecode

func stockManagement(stock []int) int {
	//二分
	left, right := 0, len(stock)-1
	for left <= right {
		mid := (left + right) >> 1
		if stock[mid] < stock[right] {
			right = mid - 1
		} else if stock[right] < stock[mid] {
			left = mid + 1
		} else {
			x := left
			for k := left + 1; k < right; k++ {
				if stock[k] < stock[x] {
					x = k
				}
			}
			return stock[x]
		}
	}
	return 0
}
